package com.zhiwen.domain.vo;

import com.zhiwen.domain.entity.Notification;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;
import java.time.LocalDateTime;

/**
 * 通知视图对象
 */
@Data
@NoArgsConstructor
public class NotificationVO implements Serializable {

    private static final long serialVersionUID = 1L;

    /**
     * 通知ID
     */
    private Long id;

    /**
     * 接收用户ID
     */
    private Long receiverId;

    /**
     * 发送用户ID
     */
    private Long senderId;

    /**
     * 发送用户信息
     */
    private UserVO sender;

    /**
     * 通知类型(1-问题回答, 2-回答评论, 3-回答被采纳, 4-内容审核, 5-系统通知)
     */
    private Integer type;

    /**
     * 类型描述
     */
    private String typeDesc;

    /**
     * 关联ID
     */
    private Long relatedId;

    /**
     * 通知标题
     */
    private String title;

    /**
     * 通知内容
     */
    private String content;

    /**
     * 已读状态(0-未读, 1-已读)
     */
    private Integer isRead;

    /**
     * 创建时间
     */
    private LocalDateTime createTime;

    /**
     * 更新时间
     */
    private LocalDateTime updateTime;

    /**
     * 根据实体构造VO
     */
    public NotificationVO(Notification notification) {
        if (notification != null) {
            this.id = notification.getId();
            this.receiverId = notification.getReceiverId();
            this.senderId = notification.getSenderId();
            this.type = notification.getType();
            this.relatedId = notification.getRelatedId();
            this.title = notification.getTitle();
            this.content = notification.getContent();
            this.isRead = notification.getIsRead();
            this.createTime = notification.getCreateTime();
            this.updateTime = notification.getUpdateTime();

            // 设置类型描述
            switch (this.type) {
                case 1:
                    this.typeDesc = "问题回答";
                    break;
                case 2:
                    this.typeDesc = "回答评论";
                    break;
                case 3:
                    this.typeDesc = "回答被采纳";
                    break;
                case 4:
                    this.typeDesc = "内容审核";
                    break;
                case 5:
                    this.typeDesc = "系统通知";
                    break;
                default:
                    this.typeDesc = "未知类型";
            }
        }
    }
}
